from manim import *
class CustomCurve(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [25, 4, 0],
            [28,-12,0],
            [43,-15,0]
        ]
        self.set_points_smoothly(points)
class CustomCurve1(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [18, 4, 0],
            [22,-12,0],
            [43,-16,0]
        ]
        self.set_points_smoothly(points)

class math1(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(6*2+1):       
            dot1=Dot([-50,5*(i-6),0]).set_opacity(0.5)
            dot2=Dot([50,5*(i-6),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(10*2+1):        
            dot3=Dot([(i-10)*5,-30,0]).set_opacity(0.5)
            dot4=Dot([(i-10)*5,30,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #镜头跟进效果 
        self.camera.frame.save_state()
         #题目出现
        text = Tex(r"\text{(张1000题9)下列反常积分中,收敛的是：}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,20,0])
        text1 = Tex(
                   r"\text{(A)}$\int _{1}^{+\infty }\dfrac{dx}{\sqrt{x^{2}-1}}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,15,0])
        text2 = Tex(
                    r"\text{(B)}$\int _{1}^{+\infty }\dfrac{dx}{\sqrt{x\left( x-1\right) }}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([22,15,0])
        text3 = Tex(
                   r"\text{(C)}$\int _{1}^{+\infty }\dfrac{dx}{x^{2}\sqrt{x^{2}-1}}$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,8,0])
        text4 = Tex(
                    r"\text{(D)}$\int _{1}^{+\infty }\dfrac{dx}{x\left( x^{2}-1\right) }$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([22,8,0])

        self.play(Write(text),Write(text1),Write(text2),Write(text3),Write(text4))
        self.wait(0.1)
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(Restore(self.camera.frame))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        #题目向上移动
        #self.play(text.animate().move_to([0,20,0]),text1.animate().move_to([-22,15,0]) ,text2.animate().move_to([22,15,0]),text3.animate().move_to([-22,8,0]),text4.animate().move_to([22,8,0]) )
         #半透明矩阵扩展
        rectangle=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-22,15,0])
        self.play(
            rectangle.animate.stretch(19.0,dim=0)
        )
        text5 = Tex(
                    r"\text{(A)瑕点为}$+\infty $\text{和}$1$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,0,0])
        self.play(Write(text5))
        text6 = Tex(
                    r"\text{当}$x\rightarrow +\infty $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-40,-5,0])
        self.play(Write(text6))
        text7 = Tex(
                    r"$\dfrac{1}{\sqrt{x^{2}-1}}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,-5,0])
        self.play(Write(text7))
        text8 = Tex(
                    r"\text{等价于}$\dfrac{1}{x}$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-5,0])
        self.play(Write(text8))

        text9 = Tex(
                    r"\text{与}$\dfrac{1}{x}$\text{同趋势}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([5,-5,0])
        self.play(Write(text9))

        text10 = Tex(
                    r"\text{(发散)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-5,0])
        self.play(Write(text10))

        text11 = Tex(
                    r"\text{当}$x\rightarrow 1 $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-40,-15,0])
        self.play(Write(text11))
        text12 = Tex(
                    r"$\dfrac{1}{\sqrt{x^{2}-1}}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,-15,0])
        self.play(Write(text12))
        text13 = Tex(
                    r"\text{等价于}$\dfrac{1}{\sqrt{2\left( x-1\right) }}$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-15,0])
        self.play(Write(text13))

        text14 = Tex(
                    r"\text{与}$\dfrac{1}{\sqrt{x-1}}$\text{同趋势}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([12,-15,0])
        self.play(Write(text14))

        text15 = Tex(
                    r"\text{(收敛)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([28,-15,0])
        self.play(Write(text15))
        self.play(Uncreate(text14),Uncreate(text13),Uncreate(text12),Uncreate(text11)
                  ,Uncreate(text10),Uncreate(text7),Uncreate(text9),Uncreate(text8)
                  ,Uncreate(text6),Uncreate(text5)
                  ,Uncreate(text15)
                  ,  rectangle.animate.set_color(RED) )
        self.wait(0.3)
        #半透明矩阵扩展
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([22,15,0])
        self.play(
            rectangle1.animate.stretch(19.0,dim=0)
        )
        #B选项

        text5 = Tex(
                    r"\text{(B)瑕点为}$+\infty $\text{和}$1$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,0,0])
        self.play(Write(text5))
        text6 = Tex(
                    r"\text{当}$x\rightarrow +\infty $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-40,-5,0])
        self.play(Write(text6))
        text7 = Tex(
                    r"$\dfrac{1}{\sqrt{x\left( x-1\right) }}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,-5,0])
        self.play(Write(text7))
        text8 = Tex(
                    r"\text{等价于}$\dfrac{1}{x}$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-5,0])
        self.play(Write(text8))

        text9 = Tex(
                    r"\text{与}$\dfrac{1}{x}$\text{同趋势}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([5,-5,0])
        self.play(Write(text9))

        text10 = Tex(
                    r"\text{(发散)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-5,0])
        self.play(Write(text10))

        text11 = Tex(
                    r"\text{当}$x\rightarrow 1 $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-40,-15,0])
        self.play(Write(text11))
        text12 = Tex(
                    r"$\dfrac{1}{\sqrt{x\left( x-1\right) }}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,-15,0])
        self.play(Write(text12))
        text13 = Tex(
                    r"\text{等价于}$\dfrac{1}{\sqrt{x-1}}$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-15,0])
        self.play(Write(text13))

        text14 = Tex(
                    r"\text{与}$\dfrac{1}{\sqrt{x-1}}$\text{同趋势}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([12,-15,0])
        self.play(Write(text14))

        text15 = Tex(
                    r"\text{(收敛)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([28,-15,0])
        self.play(Write(text15))
        self.play(Uncreate(text14),Uncreate(text13),Uncreate(text12),Uncreate(text11)
                  ,Uncreate(text10),Uncreate(text7),Uncreate(text9),Uncreate(text8)
                  ,Uncreate(text6),Uncreate(text5)
                  ,Uncreate(text15)
                  ,  rectangle1.animate.set_color(RED) )
        self.wait(0.3)
        #半透明矩阵扩展
        rectangle2=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([-22,8,0])
        self.play(
            rectangle2.animate.stretch(19.0,dim=0)
        )

        #c选项

        text5 = Tex(
                    r"\text{(C)瑕点为}$+\infty $\text{和}$1$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,0,0])
        self.play(Write(text5))
        text6 = Tex(
                    r"\text{当}$x\rightarrow +\infty $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-40,-5,0])
        self.play(Write(text6))
        text7 = Tex(
                    r"$\dfrac{1}{x^{2}\sqrt{1-x^{2}}}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,-5,0])
        self.play(Write(text7))
        text8 = Tex(
                    r"\text{等价于}$\dfrac{1}{x^{3}}$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-5,0])
        self.play(Write(text8))

        text9 = Tex(
                    r"\text{与}$\dfrac{1}{x^{3}}$\text{同趋势}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([5,-5,0])
        self.play(Write(text9))

        text10 = Tex(
                    r"\text{(收敛)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-5,0])
        self.play(Write(text10))

        text11 = Tex(
                    r"\text{当}$x\rightarrow 1 $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-40,-15,0])
        self.play(Write(text11))
        text12 = Tex(
                    r"$\dfrac{1}{x^{2}\sqrt{1-x^{2}}}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,-15,0])
        self.play(Write(text12))
        text13 = Tex(
                    r"\text{等价于}$\dfrac{1}{\sqrt{2\left( x-1\right) }}$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-7,-15,0])
        self.play(Write(text13))

        text14 = Tex(
                    r"\text{与}$\dfrac{1}{\sqrt{x-1}}$\text{同趋势}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([15,-15,0])
        self.play(Write(text14))

        text15 = Tex(
                    r"\text{(收敛)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([31,-15,0])
        self.play(Write(text15))
        self.play(Uncreate(text14),Uncreate(text13),Uncreate(text12),Uncreate(text11)
                  ,Uncreate(text10),Uncreate(text7),Uncreate(text9),Uncreate(text8)
                  ,Uncreate(text6),Uncreate(text5)
                  ,Uncreate(text15)
                  ,  rectangle2.animate.set_color(GREEN) )
        self.wait(0.3)


        #半透明矩阵扩展
        rectangle3=Rectangle(color=BLUE,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=YELLOW,stroke_width=0).move_to([22,8,0])
        self.play(
            rectangle3.animate.stretch(19.0,dim=0)
        )

        #D选项

        text5 = Tex(
                    r"\text{(C)瑕点为}$+\infty $\text{和}$1$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,0,0])
        self.play(Write(text5))
        text6 = Tex(
                    r"\text{当}$x\rightarrow +\infty $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-40,-5,0])
        self.play(Write(text6))
        text7 = Tex(
                    r"$\dfrac{1}{x^{2}\sqrt{1-x^{2}}}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,-5,0])
        self.play(Write(text7))
        text8 = Tex(
                    r"\text{等价于}$\dfrac{1}{x^{3}}$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-5,0])
        self.play(Write(text8))

        text9 = Tex(
                    r"\text{与}$\dfrac{1}{x^{3}}$\text{同趋势}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([5,-5,0])
        self.play(Write(text9))

        text10 = Tex(
                    r"\text{(收敛)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-5,0])
        self.play(Write(text10))

        text11 = Tex(
                    r"\text{当}$x\rightarrow 1 $",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-40,-15,0])
        self.play(Write(text11))
        text12 = Tex(
                    r"$\dfrac{1}{x^{2}\sqrt{1-x^{2}}}$",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,-15,0])
        self.play(Write(text12))
        text13 = Tex(
                    r"\text{等价于}$\dfrac{1}{2x}$",color=PURPLE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-10,-15,0])
        self.play(Write(text13))

        text14 = Tex(
                    r"\text{与}$\dfrac{1}{x}$\text{同趋势}",color=BLUE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([5,-15,0])
        self.play(Write(text14))

        text15 = Tex(
                    r"\text{(发散)}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-15,0])
        self.play(Write(text15))
        self.play(Uncreate(text14),Uncreate(text13),Uncreate(text12),Uncreate(text11)
                  ,Uncreate(text10),Uncreate(text7),Uncreate(text9),Uncreate(text8)
                  ,Uncreate(text6),Uncreate(text5)
                  ,Uncreate(text15)
                  ,  rectangle3.animate.set_color(RED) )
        self.wait(0.3)







        self.wait()